﻿#region :: File Specification ::
/************************ Code File Header ****************************
Author:       v0cn306 Archer Chen    
Date:           2012 June 28
Description: Use auto mapper to convert between business models and data entities. 

Modification History:
Editor                    Date                      Comment

*******************************************************************/
#endregion
      
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using CodeStudy.AutoMapper.BusinessModels;
using CodeStudy.AutoMapper.DataEntities;

namespace CodeStudy.AutoMapper
{
    public class AutoMapperLearning
    {
        /// <summary>
        /// Initialization state flag
        /// </summary>
        private static bool _initialized = false;

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public static void Initialize()
        {
            if (!_initialized)
            {
                Mapper.CreateMap<Order, OrderDE>().ForMember("ID", opt => opt.MapFrom(src => src.OrderID));
                Mapper.CreateMap<OrderDE, Order>();

                Mapper.CreateMap<OrderLine, OrderLineDE>();
                Mapper.CreateMap<Customer, CustomerDE>();
                Mapper.CreateMap<Product, ProductDE>();
                _initialized = true;
            }
        }

    }
}
